//package com.zzt.community.controller.interceptor;
//
//import com.zzt.community.util.HostHolder;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import java.lang.reflect.Method;
//
///**
// * Classname: LoginRequiredInterceptor
// * Package: com.zzt.community.controller.interceptor
// * Description:
// *
// * @Author:zzt
// * @Create: 2024/3/10-23:35
// * Version:
// */
//@Component
//public class LoginRequiredInterceptor implements HandlerInterceptor {
//
//    @Autowired
//    private HostHolder hostHolder;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        if (handler instanceof HandlerMethod) {
//            HandlerMethod handlerMethod = (HandlerMethod) handler;
//            Method method = handlerMethod.getMethod();
//            LoginRequired loginRequired = method.getAnnotation(LoginRequired.class);
//            if (loginRequired != null && hostHolder.getUser() == null) {
//                response.sendRedirect(request.getContextPath() + "/login");
//                return false;
//            }
//        }
//        return true;
//    }
//}
